package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ChatUser;
import com.ruoyi.system.service.IChatUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 聊天用户Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/system/chatUser")
public class ChatUserController extends BaseController
{
    @Autowired
    private IChatUserService chatUserService;

    /**
     * 查询聊天用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:chatUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatUser chatUser)
    {
        startPage();
        List<ChatUser> list = chatUserService.selectChatUserList(chatUser);
        return getDataTable(list);
    }

    /**
     * 导出聊天用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:chatUser:export')")
    @Log(title = "聊天用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatUser chatUser)
    {
        List<ChatUser> list = chatUserService.selectChatUserList(chatUser);
        ExcelUtil<ChatUser> util = new ExcelUtil<ChatUser>(ChatUser.class);
        util.exportExcel(response, list, "聊天用户数据");
    }

    /**
     * 获取聊天用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chatUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(chatUserService.selectChatUserByUserId(userId));
    }

    /**
     * 新增聊天用户
     */
    @PreAuthorize("@ss.hasPermi('system:chatUser:add')")
    @Log(title = "聊天用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatUser chatUser)
    {
        return toAjax(chatUserService.insertChatUser(chatUser));
    }

    /**
     * 修改聊天用户
     */
    @PreAuthorize("@ss.hasPermi('system:chatUser:edit')")
    @Log(title = "聊天用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatUser chatUser)
    {
        return toAjax(chatUserService.updateChatUser(chatUser));
    }

    /**
     * 删除聊天用户
     */
    @PreAuthorize("@ss.hasPermi('system:chatUser:remove')")
    @Log(title = "聊天用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(chatUserService.deleteChatUserByUserIds(userIds));
    }
}
